package com.leyou.auth.config;

import com.leyou.common.auth.utils.RsaUtils;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;

import javax.annotation.PostConstruct;
import java.security.PrivateKey;
import java.security.PublicKey;

@Data
@Slf4j
@ConfigurationProperties(prefix = "ly.jwt")
public class JwtProperties {
    //公钥地址
    private String pubKeyPath;
    //私钥地址
    private String priKeyPath;

    //用户token相关属性
    private PublicKey publicKey;
    private PrivateKey privateKey;

    private AuthUser user = new AuthUser();

    @Data
    public class AuthUser{
        //token过期时长
        private Integer expire;
        //存放token的cookie名称
        private String cookieName;
        //存放token的cookie的域名
        private String cookieDomain;
        //token的刷新时间
        private Integer refreshTime;
    }
     //用户token相关属性的构造方法
    @PostConstruct
    public void createKey() throws Exception {
        this.publicKey = RsaUtils.getPublicKey(pubKeyPath);
        this.privateKey = RsaUtils.getPrivateKey(priKeyPath);
    }

}








